package com.mbc.controller;


import com.github.pagehelper.PageInfo;
import com.mbc.comment.Result;
import com.mbc.pojo.MbcConcern;
import com.mbc.service.ConcernService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 关注表 前端控制器
 * </p>
 *
 * @author suimeng
 * @since 2024-04-08
 */
@RestController
@RequestMapping("/concern")
@Api(tags = "关注接口")
@CrossOrigin
public class ConcernController {

    @Autowired
    private ConcernService concernService;

    /**
     *
     * 分页查询关注列表
     *
     *
     * @param userId 用户 ID
     * @param page   页
     * @param size   大小
     * @return {@link Result}<{@link List}<{@link MbcConcern}>>
     */
    @GetMapping("/{userId}")
    @ApiOperation("分页查询关注列表")
    public Result<PageInfo<MbcConcern>> listFollowers(@PathVariable String userId, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size){
        PageInfo<MbcConcern> list = concernService.getAllByuserId(userId,page,size);
        return Result.success(list);
    }

    /**
     * 删除关注 ID
     *
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/delete/{concernId}")
    @ApiOperation("删除关注的ID")
    public Result<Boolean> deleteConcernId(@PathVariable Integer concernId ){
         return Result.success(concernService.deleteConcernId(concernId));

    }


    /**
     * 新增用户
     *
     * @param userId    用户 ID
     * @param concernId 关注点 ID
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/insert/{userId}/{concernId}")
    @ApiOperation("新增用户")
    public Result<Boolean> insertConcern(@PathVariable Integer userId,@PathVariable Integer concernId){
        return Result.success(concernService.insertConcern(userId,concernId));
    }
}
